# 产品
class Document:
    def __init__(self):
        self.parts = []

    def add_part(self, part):
        self.parts.append(part)

    def show_document(self):
        for part in self.parts:
            print(part)


# 生成器接口
class DocumentBuilder:
    def add_title(self, title):
        pass

    def add_body(self, body):
        pass

    def add_footer(self, footer):
        pass

    def get_document(self):
        pass


# 具体生成器
class MyDocumentBuilder(DocumentBuilder):
    def __init__(self):
        self.document = Document()

    def add_title(self, title):
        self.document.add_part(f"Title: {title}")

    def add_body(self, body):
        self.document.add_part(f"Body: {body}")

    def add_footer(self, footer):
        self.document.add_part(f"Footer: {footer}")

    def get_document(self):
        return self.document


# 指导者
class Director:
    def __init__(self, builder):
        self.builder = builder

    def construct_document(self):
        self.builder.add_title("Hello World")
        self.builder.add_body("This is an example of the Builder Pattern.")
        self.builder.add_footer("Footer of the Document")


# 客户端代码
builder = MyDocumentBuilder()
director = Director(builder)
director.construct_document()

document = builder.get_document()
document.show_document()

'''
Title: Hello World
Body: This is an example of the Builder Pattern.
Footer: Footer of the Document
'''